﻿using System.Net;
using System.Text;
using CoreLibrary;

namespace Modules.Tracking.API {

    public class AuOneExpressAPI : IShipmentAPI {

        const string TrackUrl = "http://www.expressone.com.au/zh-cn/ajax.php?id=";

        public string Track(string trackingId) {
            var url = TrackUrl + trackingId;
            var request = CreateGetRequest(url);
            using (var response = (HttpWebResponse) request.GetResponse()) {
                return Encoding.UTF8.GetString(IOUtil.Read(response.GetResponseStream()));
            }
        }

        protected static HttpWebRequest CreateGetRequest(string url) {
            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method           = "GET";
            request.ProtocolVersion  = HttpVersion.Version11;
            request.Timeout          = 500000000;
            request.ReadWriteTimeout = 500000000;
            return request;
        }
    }
}